/*
This do-file contains code to replicate results in
"State As Salesman: International  Economic Engagement and Foreign News Coverage in China."
*/


use "news_fav.dta"
xtset ccodecow year

global covars = "ccscale visits libdem conflict rle pve gee agency"


****************************
**** RESULTS IN ARTICLE ****
****************************


****** TABLE 1 ********
* Panel A
eststo: qui xtreg score1 i.year lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear
* Panel B
eststo: qui xtreg score1 i.year $covars lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** TABLE 2 ******
/*
topic1: human-made accidents
topic2: armed conflict
topic3: culture
topic4: diplomacy
topic5: natural disaster
topic6: economy
topic7: international cooperation and security
topic8: domestic politics
topic9: sports
topic10:science and tech
*/
foreach var of varlist lnfreq8 lnfreq6 lnfreq2 lnfreq3 lnfreq4 {
   eststo: qui xtreg `var' lnexport fossil lnproject i.year ,fe vce(cluster ccodecow)
}
esttab est1 est2 est3 est4 est5, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** FIGURE 4 ******
* plot (a)
xtreg score1 c.lnexport##i.year, fe vce(cluster ccodecow)
margins, dydx(lnexport) over(year)
marginsplot
* plot(b) 
xtreg score1 i.fossil##i.year, fe vce(cluster ccodecow)
margins, dydx(fossil) over(year)
marginsplot
* plot (c) 
xtreg score1 c.lnproject##i.year, fe vce(cluster ccodecow)
margins, dydx(lnproject) over(year)
marginsplot


****** FIGURE 5 ******
* plot (a)
interflex score1 conflict lnexport,  type(binning) n(3) fe(ccodecow year) cluster(ccodecow) vce(cluster ccodecow) ylab(Coverage Favorability) dlab(Conflict) xlab(Export)  yrange(-30, 10) title("(a)")
* plot (b)
interflex score1 conflict lnproject, type(binning) n(3) fe(ccodecow year) cluster(ccodecow) vce(cluster ccodecow) ylab(Coverage Favorability) dlab(Conflict) xlab(Overseas Projects)  yrange(-30, 10) title("(b)")



*******************************
***** RESULTS IN APPENDIX *****
*******************************

****** TABLE B4 ********
eststo: qui xtreg score1 i.year ccscale,       fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year idealpoint,    fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year pctagreechina, fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year pctagreeus,    fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year ccscale idealpoint pctagreechina pctagreeus,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear

****** TABLE B5 ********
eststo: qui xtreg score1 i.year libdem, fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year p_polity2, fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year libdem p_polity2, fe vce(cluster ccodecow)
esttab est1 est2 est3, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear

****** TABLE B6 ********
eststo: qui xtreg score1 i.year conflict,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year vae,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year rqe,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year rle lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year pve,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year gee,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year cce,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year conflict vae rqe rle pve gee cce,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear

****** TABLE B7 ********
eststo: qui xtreg score1 i.year $covars lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** TABLE B8 ********
* Panel A
foreach var of varlist lnfreq2 lnfreq8 lnfreq4 lnfreq6 lnfreq5 lnfreq1 lnfreq7 lnfreq10 lnfreq9 lnfreq3 { 
	eststo: qui xtreg `var' lnexport fossil lnproject i.year ,fe vce(cluster ccodecow)
}
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 est10, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear
* Panel B
foreach var of varlist lnfreq2 lnfreq8 lnfreq4 lnfreq6 lnfreq5 lnfreq1 lnfreq7 lnfreq10 lnfreq9 lnfreq3 { 
	eststo: qui xtreg `var' lnexport fossil lnproject $covars i.year, fe vce(cluster ccodecow)
}
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 est10, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear

****** TABLE B9 ********
global covars2 = "ccscale visits libdem conflict rle pve gee lngdp agency"
eststo: qui xtreg score1 i.year $covars2 lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year $covars2 lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** TABLE B10 ********
eststo: qui xtreg score1 i.year lnexport fossil lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport fossil lnproject $covars, fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year L.lnexport L.fossil L.lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year L.lnexport L.fossil L.lnproject $covars, fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport L.lnexport fossil L.fossil lnproject L.lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score1 i.year lnexport L.lnexport fossil L.fossil lnproject L.lnproject $covars, fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** TABLE B11 ********
* Panel A
eststo: qui xtreg score3 i.year lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score3 i.year lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear
* Panel B
eststo: qui xtreg score2 i.year lntrade,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnexport,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnexport lnimport,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year fossil,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnfdi,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnproject,fe vce(cluster ccodecow)
eststo: qui xtreg score2 i.year lnexport fossil lnproject,fe vce(cluster ccodecow)
esttab est1 est2 est3 est4 est5 est6 est7 est8, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** TABLE B12 ********
* Panel A
foreach var of varlist score_ex2 score_ex8 score_ex4 score_ex6 score_ex5 score_ex1 score_ex7 score_ex10 score_ex9 score_ex3 { 
	eststo: qui xtreg `var' lnexport fossil lnproject i.year, fe vce(cluster ccodecow)
}
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 est10, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear
* Panel B
foreach var of varlist score_ex2 score_ex8 score_ex4 score_ex6 score_ex5 score_ex1 score_ex7 score_ex10 score_ex9 score_ex3 { 
	eststo: qui xtreg `var' lnexport fossil lnproject $covars i.year, fe vce(cluster ccodecow)
}
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 est10, se ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear


****** FIGURE B1 ********
* plot (a)
xtreg score1 i.fossil##c.lnexport $covars i.year ,fe cluster(ccodecow)
margins , at(lnexport=(1(1)20) fossil=(0 1)) atmeans
marginsplot, recast(line) recastci(rarea) ciopts(fcolor(%30) lcolor(%1)) title("") ytitle("Point Estimate") yline(0) xtitle("Export") xlabel(0 (2) 21) legend(order(1 "Fossil = 0" 2 "Fossil = 1" )) plot1opts(lpattern(dash)) plot2opts(lpattern(solid)) title("(a)")
* plot (b)
xtreg score1 i.fossil##c.lnproject $covars i.year ,fe cluster(ccodecow)
margins , at(lnproject=(0(1)14) fossil=(0 1)) atmeans
marginsplot, recast(line) recastci(rarea) ciopts(fcolor(%30) lcolor(%1)) title("") ytitle("Point Estimate")  ylabel(-20 (20) 30) yline(0) xtitle("Overseas Projects") xlabel(0 (2) 14.5) legend(order(1 "Fossil = 0" 2 "Fossil = 1" )) plot1opts(lpattern(dash)) plot2opts(lpattern(solid)) title("(b)")


****** FIGURE B2 ********
* plot (a)
kdensity score1
* plot (b)
kdensity score4
* plot (c)
kdensity score3
